<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>BroadcastChannel Example</title>
</head>
<body>
<script src="./index.js"></script>
<script>
  let index = 0

  function BroadcastCallback() {
    console.log(12, 'index.html')
  }
  const channel = new Channel('example_channel', BroadcastCallback)

  const send = () => {
    console.log(20, channel.listeners)
    if (channel.listeners.size === 0) {
      window.open('/b.html', '_blank')
    } else {
      const res = confirm('您将更新b.html')
      if (res) {
        channel.postMsg({
          data: index,
          data2: index
        })
        index++
      } else {
        window.alert('您已取消')
        return
      }
    }
  }
</script>

<button onclick="send()">点击新建或更新</button>

</body>
</html>
